package com.jc.camerascan.activity;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jc.camerascan.R;
import com.jc.camerascan.adapter.ScanResultEightAdapter;
import com.jc.camerascan.adapter.ScanResultElevenAdapter;
import com.jc.camerascan.adapter.ScanResultFifteenAdapter;
import com.jc.camerascan.adapter.ScanResultFiveAdapter;
import com.jc.camerascan.adapter.ScanResultFourAdapter;
import com.jc.camerascan.adapter.ScanResultFourteenAdapter;
import com.jc.camerascan.adapter.ScanResultNineAdapter;
import com.jc.camerascan.adapter.ScanResultOneAdapter;
import com.jc.camerascan.adapter.ScanResultSevenAdapter;
import com.jc.camerascan.adapter.ScanResultSixAdapter;
import com.jc.camerascan.adapter.ScanResultTenAdapter;
import com.jc.camerascan.adapter.ScanResultThirteenAdapter;
import com.jc.camerascan.adapter.ScanResultThreeAdapter;
import com.jc.camerascan.adapter.ScanResultTwelveAdapter;
import com.jc.camerascan.adapter.ScanResultTwoAdapter;
import com.jc.camerascan.core.BaseActivity;
import com.jc.camerascan.core.http.bean.CustomApiResult;
import com.jc.camerascan.core.http.callback.TipCallBack;
import com.jc.camerascan.entity.AdvancedResult;
import com.jc.camerascan.entity.AnimalDetectResult;
import com.jc.camerascan.entity.BankcardResult;
import com.jc.camerascan.entity.BusinessCard;
import com.jc.camerascan.entity.BusinessLicenseResult;
import com.jc.camerascan.entity.DrivingLicenseResult;
import com.jc.camerascan.entity.GeneralBasicResult;
import com.jc.camerascan.entity.HouseholdRegisterResult;
import com.jc.camerascan.entity.IdcardResult;
import com.jc.camerascan.entity.IdcardSideResult;
import com.jc.camerascan.entity.LandmarkResult;
import com.jc.camerascan.entity.LicensePlateResult;
import com.jc.camerascan.entity.PassportResult;
import com.jc.camerascan.entity.QrcodeResult;
import com.jc.camerascan.entity.TableRecognitionResult;
import com.jc.camerascan.entity.UpLoadImageOne;
import com.jc.camerascan.entity.UpLoadImageTwo;
import com.jc.camerascan.utils.ImageUtil;
import com.jc.camerascan.utils.Utils;
import com.jc.camerascan.utils.XToastUtils;
import com.xuexiang.xhttp2.XHttp;
import com.xuexiang.xhttp2.callback.CallBackProxy;
import com.xuexiang.xhttp2.exception.ApiException;
import com.xuexiang.xui.utils.WidgetUtils;
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.dialog.LoadingDialog;
import com.xuexiang.xui.widget.textview.supertextview.SuperButton;
import com.xuexiang.xutil.net.JsonUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @ProjectName: PhotoRecognition
 * @Package: com.jc.camerascan.activity
 * @ClassName: ScanResultActivity
 * @Description: 识别结果
 * @Author: XuChi
 * @CreateDate: 2020/7/15 18:04
 * @Version: 1.0
 */
public class ScanResultActivity extends BaseActivity {

    @BindView(R.id.img)
    ImageView img;
    @BindView(R.id.list)
    RecyclerView list;
    @BindView(R.id.copy)
    SuperButton copy;

    private String path = "";

    private LoadingDialog mLoadingDialog;

    private String scanType = "";

    private int idCardType = 0;

    public static void start(Context context, String path, String scanType) {
        Intent intent = new Intent(context, ScanResultActivity.class);
        intent.putExtra("path", path);
        intent.putExtra("scanType", scanType);
        context.startActivity(intent);
    }

    public static void start(Context context, String path, String scanType, int idCardType) {
        Intent intent = new Intent(context, ScanResultActivity.class);
        intent.putExtra("path", path);
        intent.putExtra("scanType", scanType);
        intent.putExtra("idCardType", idCardType);
        context.startActivity(intent);
    }


    @BindView(R.id.titlebar)
    TitleBar titlebar;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_scan_result;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    private void initView() {
        path = getIntent().getStringExtra("path");
        scanType = getIntent().getStringExtra("scanType");
        idCardType = getIntent().getIntExtra("idCardType", 0);
        titlebar.setTitle("识别结果");
        titlebar.setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //配置布局，默认为vertical（垂直布局），下边这句将布局改为水平布局
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        list.setLayoutManager(layoutManager);
//        list.addItemDecoration(new SpaceItemDecoration(5, 0));
//        list.addItemDecoration(new GridSpacingItemDecoration(3, DensityUtils.dp2px(getActivity(), 5), false));
        list.setNestedScrollingEnabled(false);
        list.setHasFixedSize(false);

        ImageUtil.loadImage(this, path, img);
        upLoadImage(path);
    }

    private void upLoadImage(String imgPath) {
        mLoadingDialog = WidgetUtils.getLoadingDialog(this)
                .setIconScale(0.4F)
                .setLoadingSpeed(8);
        mLoadingDialog.show();
        if (scanType.contains("QNSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Image/Advanced")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<AdvancedResult>, AdvancedResult>(new TipCallBack<AdvancedResult>() {
                        @Override
                        public void onSuccess(AdvancedResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultOneAdapter scanResultOneAdapter = new ScanResultOneAdapter();
                            list.setAdapter(scanResultOneAdapter);
                            scanResultOneAdapter.setNewData(response.getResult());
                            copy.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("DBSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Image/Landmark")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<LandmarkResult>, LandmarkResult>(new TipCallBack<LandmarkResult>() {
                        @Override
                        public void onSuccess(LandmarkResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultTwoAdapter scanResultTwoAdapter = new ScanResultTwoAdapter();
                            list.setAdapter(scanResultTwoAdapter);
                            List<LandmarkResult.ResultBean> data = new ArrayList<>();
                            data.add(response.getResult());
                            scanResultTwoAdapter.setNewData(data);
                            copy.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("DWSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Image/AnimalDetect")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<AnimalDetectResult>, AnimalDetectResult>(new TipCallBack<AnimalDetectResult>() {
                        @Override
                        public void onSuccess(AnimalDetectResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultThreeAdapter scanResultThreeAdapter = new ScanResultThreeAdapter();
                            list.setAdapter(scanResultThreeAdapter);
                            scanResultThreeAdapter.setNewData(response.getResult());
                            copy.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("ZWSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Image/PlantDetect")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<AnimalDetectResult>, AnimalDetectResult>(new TipCallBack<AnimalDetectResult>() {
                        @Override
                        public void onSuccess(AnimalDetectResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultThreeAdapter scanResultThreeAdapter = new ScanResultThreeAdapter();
                            list.setAdapter(scanResultThreeAdapter);
                            scanResultThreeAdapter.setNewData(response.getResult());
                            copy.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("CPSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Image/DishDetect")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<AnimalDetectResult>, AnimalDetectResult>(new TipCallBack<AnimalDetectResult>() {
                        @Override
                        public void onSuccess(AnimalDetectResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultThreeAdapter scanResultThreeAdapter = new ScanResultThreeAdapter();
                            list.setAdapter(scanResultThreeAdapter);
                            scanResultThreeAdapter.setNewData(response.getResult());
                            copy.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("QCSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Image/CarDetect")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<AnimalDetectResult>, AnimalDetectResult>(new TipCallBack<AnimalDetectResult>() {
                        @Override
                        public void onSuccess(AnimalDetectResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultThreeAdapter scanResultThreeAdapter = new ScanResultThreeAdapter();
                            list.setAdapter(scanResultThreeAdapter);
                            scanResultThreeAdapter.setNewData(response.getResult());
                            copy.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("PTSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/GeneralBasic")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<GeneralBasicResult>, GeneralBasicResult>(new TipCallBack<GeneralBasicResult>() {
                        @Override
                        public void onSuccess(GeneralBasicResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFourAdapter scanResultFourAdapter = new ScanResultFourAdapter();
                            list.setAdapter(scanResultFourAdapter);
                            scanResultFourAdapter.setNewData(response.getWords_result());
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    List<GeneralBasicResult.WordsResultBean> words = response.getWords_result();
                                    String word = "";
                                    if (words != null && !words.isEmpty()) {
                                        for (int i = 0; i < words.size(); i++) {
                                            if (i == 0) {
                                                word = word + words.get(i).getWords();
                                            } else {
                                                word = word + " " + words.get(i).getWords();
                                            }
                                        }
                                    }
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(word);
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("JZSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/AccurateBasic")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<GeneralBasicResult>, GeneralBasicResult>(new TipCallBack<GeneralBasicResult>() {
                        @Override
                        public void onSuccess(GeneralBasicResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFourAdapter scanResultFourAdapter = new ScanResultFourAdapter();
                            list.setAdapter(scanResultFourAdapter);
                            scanResultFourAdapter.setNewData(response.getWords_result());
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    List<GeneralBasicResult.WordsResultBean> words = response.getWords_result();
                                    String word = "";
                                    if (words != null && !words.isEmpty()) {
                                        for (int i = 0; i < words.size(); i++) {
                                            if (i == 0) {
                                                word = word + words.get(i).getWords();
                                            } else {
                                                word = word + " " + words.get(i).getWords();
                                            }
                                        }
                                    }
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(word);
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("WDSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/AccurateBasic")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<GeneralBasicResult>, GeneralBasicResult>(new TipCallBack<GeneralBasicResult>() {
                        @Override
                        public void onSuccess(GeneralBasicResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFourAdapter scanResultFourAdapter = new ScanResultFourAdapter();
                            list.setAdapter(scanResultFourAdapter);
                            scanResultFourAdapter.setNewData(response.getWords_result());
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    List<GeneralBasicResult.WordsResultBean> words = response.getWords_result();
                                    String word = "";
                                    if (words != null && !words.isEmpty()) {
                                        for (int i = 0; i < words.size(); i++) {
                                            if (i == 0) {
                                                word = word + words.get(i).getWords();
                                            } else {
                                                word = word + " " + words.get(i).getWords();
                                            }
                                        }
                                    }
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(word);
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("BGSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageTwo bean = new UpLoadImageTwo();
            bean.setBase64Str(base64Str);
            bean.setResultType(1);
            XHttp.post("/api/Text/TableRecognition")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<TableRecognitionResult>, TableRecognitionResult>(new TipCallBack<TableRecognitionResult>() {
                        @Override
                        public void onSuccess(TableRecognitionResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFiveAdapter scanResultFiveAdapter = new ScanResultFiveAdapter();
                            list.setAdapter(scanResultFiveAdapter);
                            List<TableRecognitionResult.ResultBean> data = new ArrayList<>();
                            data.add(response.getResult());
                            scanResultFiveAdapter.setNewData(data);
                            copy.setVisibility(View.VISIBLE);
                            copy.setText("点击下载");
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    TableRecognitionResult.ResultBean words = response.getResult();
                                    String url = words.getResult_data() + ".xls";
                                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                                    startActivity(browserIntent);
//                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
//                                    // 将文本内容放到系统剪贴板里。
//                                    cm.setText(words.getResult_data() + ".xls");
//                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });
        } else if (scanType.contains("SZSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/Numbers")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<GeneralBasicResult>, GeneralBasicResult>(new TipCallBack<GeneralBasicResult>() {
                        @Override
                        public void onSuccess(GeneralBasicResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFourAdapter scanResultFourAdapter = new ScanResultFourAdapter();
                            list.setAdapter(scanResultFourAdapter);
                            scanResultFourAdapter.setNewData(response.getWords_result());
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    List<GeneralBasicResult.WordsResultBean> words = response.getWords_result();
                                    String word = "";
                                    if (words != null && !words.isEmpty()) {
                                        for (int i = 0; i < words.size(); i++) {
                                            if (i == 0) {
                                                word = word + words.get(i).getWords();
                                            } else {
                                                word = word + " " + words.get(i).getWords();
                                            }
                                        }
                                    }
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(word);
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("SXWZ")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/Handwriting")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<GeneralBasicResult>, GeneralBasicResult>(new TipCallBack<GeneralBasicResult>() {
                        @Override
                        public void onSuccess(GeneralBasicResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFourAdapter scanResultFourAdapter = new ScanResultFourAdapter();
                            list.setAdapter(scanResultFourAdapter);
                            scanResultFourAdapter.setNewData(response.getWords_result());
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    List<GeneralBasicResult.WordsResultBean> words = response.getWords_result();
                                    String word = "";
                                    if (words != null && !words.isEmpty()) {
                                        for (int i = 0; i < words.size(); i++) {
                                            if (i == 0) {
                                                word = word + words.get(i).getWords();
                                            } else {
                                                word = word + " " + words.get(i).getWords();
                                            }
                                        }
                                    }
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(word);
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("EWMSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/Qrcode")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<QrcodeResult>, QrcodeResult>(new TipCallBack<QrcodeResult>() {
                        @Override
                        public void onSuccess(QrcodeResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultSixAdapter scanResultSixAdapter = new ScanResultSixAdapter();
                            list.setAdapter(scanResultSixAdapter);
                            scanResultSixAdapter.setNewData(response.getCodes_result());
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    List<QrcodeResult.CodesResultBean> words = response.getCodes_result();
                                    String word = "";
                                    if (words != null && !words.isEmpty()) {
                                        for (int i = 0; i < words.size(); i++) {
                                            if (i == 0) {
                                                word = word + words.get(i).getText();
                                            } else {
                                                word = word + " " + words.get(i).getText();
                                            }
                                        }
                                    }
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(word);
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("PZFY")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/AccurateBasic")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<GeneralBasicResult>, GeneralBasicResult>(new TipCallBack<GeneralBasicResult>() {
                        @Override
                        public void onSuccess(GeneralBasicResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFourAdapter scanResultFourAdapter = new ScanResultFourAdapter();
                            list.setAdapter(scanResultFourAdapter);
                            scanResultFourAdapter.setNewData(response.getWords_result());
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    List<GeneralBasicResult.WordsResultBean> words = response.getWords_result();
                                    String word = "";
                                    if (words != null && !words.isEmpty()) {
                                        for (int i = 0; i < words.size(); i++) {
                                            if (i == 0) {
                                                word = word + words.get(i).getWords();
                                            } else {
                                                word = word + " " + words.get(i).getWords();
                                            }
                                        }
                                    }
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(word);
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("SFZSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            if (idCardType == 0) {
                XHttp.post("/api/Text/Idcard")
                        .upJson(JsonUtil.toJson(bean))
                        .execute(new CallBackProxy<CustomApiResult<IdcardResult>, IdcardResult>(new TipCallBack<IdcardResult>() {
                            @Override
                            public void onSuccess(IdcardResult response) {
                                mLoadingDialog.dismiss();
                                ScanResultNineAdapter scanResultNineAdapter = new ScanResultNineAdapter();
                                list.setAdapter(scanResultNineAdapter);
                                List<IdcardResult.WordsResultBean> data = new ArrayList<>();
                                data.add(response.getWords_result());
                                scanResultNineAdapter.setNewData(data);
                                copy.setVisibility(View.VISIBLE);
                                copy.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        IdcardResult.WordsResultBean words = response.getWords_result();
                                        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                        // 将文本内容放到系统剪贴板里。
                                        cm.setText(words.getName() + " " + words.getBirthday() + " " + words.getAddress() + " " + words.getIdnumber() + " " + words.getNation() + " " + words.getSex());
                                        XToastUtils.success("复制成功");
                                    }
                                });
                            }

                            @Override
                            public void onError(ApiException e) {
                                super.onError(e);
                                mLoadingDialog.dismiss();
                            }
                        }) {
                        });
            } else {
                XHttp.post("/api/Text/IdcardSide")
                        .upJson(JsonUtil.toJson(bean))
                        .execute(new CallBackProxy<CustomApiResult<IdcardSideResult>, IdcardSideResult>(new TipCallBack<IdcardSideResult>() {
                            @Override
                            public void onSuccess(IdcardSideResult response) {
                                mLoadingDialog.dismiss();
                                ScanResultTenAdapter scanResultTenAdapter = new ScanResultTenAdapter();
                                list.setAdapter(scanResultTenAdapter);
                                List<IdcardSideResult.WordsResultBean> data = new ArrayList<>();
                                data.add(response.getWords_result());
                                scanResultTenAdapter.setNewData(data);
                                copy.setVisibility(View.VISIBLE);
                                copy.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        IdcardSideResult.WordsResultBean words = response.getWords_result();
                                        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                        // 将文本内容放到系统剪贴板里。
                                        cm.setText(words.getQfjg() + " " + words.getSxsj() + " " + words.getQfrq());
                                        XToastUtils.success("复制成功");
                                    }
                                });
                            }

                            @Override
                            public void onError(ApiException e) {
                                super.onError(e);
                                mLoadingDialog.dismiss();
                            }
                        }) {
                        });
            }

        } else if (scanType.contains("YYZZ")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/BusinessLicense")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<BusinessLicenseResult>, BusinessLicenseResult>(new TipCallBack<BusinessLicenseResult>() {
                        @Override
                        public void onSuccess(BusinessLicenseResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultElevenAdapter scanResultElevenAdapter = new ScanResultElevenAdapter();
                            list.setAdapter(scanResultElevenAdapter);
                            List<BusinessLicenseResult.WordsResultBean> data = new ArrayList<>();
                            data.add(response.getWords_result());
                            scanResultElevenAdapter.setNewData(data);
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    BusinessLicenseResult.WordsResultBean words = response.getWords_result();
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(words.getClrq() + " " + words.getYxq() + " " + words.getJyfw() + " " + words.getDz() + " " + words.getZcxs() + " " + words.getZjbh() + " " + words.getFr() + " " + words.getShxydm() + " " + words.getZczb() + " " + words.getLx() + " " + words.getDwmc());
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("MPSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/BusinessCard")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<BusinessCard>, BusinessCard>(new TipCallBack<BusinessCard>() {
                        @Override
                        public void onSuccess(BusinessCard response) {
                            mLoadingDialog.dismiss();
                            ScanResultTwelveAdapter scanResultTwelveAdapter = new ScanResultTwelveAdapter();
                            list.setAdapter(scanResultTwelveAdapter);
                            List<BusinessCard.WordsResultBean> data = new ArrayList<>();
                            data.add(response.getWords_result());
                            scanResultTwelveAdapter.setNewData(data);
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    BusinessCard.WordsResultBean words = response.getWords_result();
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(words.getADDR() + " " + words.getURL() + " " + words.getMOBILE() + " " + words.getCOMPANY() + " " + words.getFAX() + " " + words.getTEL() + " " + words.getTITLE() + " " + words.getNAME() + " " + words.getEMAIL() + " " + words.getPC());
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("YHK")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/Bankcard")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<BankcardResult>, BankcardResult>(new TipCallBack<BankcardResult>() {
                        @Override
                        public void onSuccess(BankcardResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultEightAdapter scanResultEightAdapter = new ScanResultEightAdapter();
                            list.setAdapter(scanResultEightAdapter);
                            List<BankcardResult.ResultBean> data = new ArrayList<>();
                            data.add(response.getResult());
                            scanResultEightAdapter.setNewData(data);
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    BankcardResult.ResultBean words = response.getResult();
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(words.getBank_card_number() + " " + words.getBank_name());
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("JSZ")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/DrivingLicense")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<DrivingLicenseResult>, DrivingLicenseResult>(new TipCallBack<DrivingLicenseResult>() {
                        @Override
                        public void onSuccess(DrivingLicenseResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultThirteenAdapter scanResultThirteenAdapter = new ScanResultThirteenAdapter();
                            list.setAdapter(scanResultThirteenAdapter);
                            List<DrivingLicenseResult.WordsResultBean> data = new ArrayList<>();
                            data.add(response.getWords_result());
                            scanResultThirteenAdapter.setNewData(data);
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    DrivingLicenseResult.WordsResultBean words = response.getWords_result();
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(words.getCclzsj() + " " + words.getYxqx() + " " + words.getXb() + " " + words.getZjcx() + " " + words.getGj() + " " + words.getZz() + " " + words.getZh() + " " + words.getCsrq() + " " + words.getXm());
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("CARPSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/LicensePlate")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<LicensePlateResult>, LicensePlateResult>(new TipCallBack<LicensePlateResult>() {
                        @Override
                        public void onSuccess(LicensePlateResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultSevenAdapter scanResultSevenAdapter = new ScanResultSevenAdapter();
                            list.setAdapter(scanResultSevenAdapter);
                            scanResultSevenAdapter.setNewData(response.getWords_result());
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    List<LicensePlateResult.WordsResultBean> words = response.getWords_result();
                                    String word = "";
                                    if (words != null && !words.isEmpty()) {
                                        for (int i = 0; i < words.size(); i++) {
                                            if (i == 0) {
                                                word = word + words.get(i).getNumber();
                                            } else {
                                                word = word + " " + words.get(i).getNumber();
                                            }
                                        }
                                    }
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(word);
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("HZSB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/Passport")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<PassportResult>, PassportResult>(new TipCallBack<PassportResult>() {
                        @Override
                        public void onSuccess(PassportResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFourteenAdapter scanResultFourteenAdapter = new ScanResultFourteenAdapter();
                            list.setAdapter(scanResultFourteenAdapter);
                            List<PassportResult.WordsResultBean> data = new ArrayList<>();
                            data.add(response.getWords_result());
                            scanResultFourteenAdapter.setNewData(data);
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    PassportResult.WordsResultBean words = response.getWords_result();
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(words.getCsdd() + " " + words.getXb() + " " + words.getSr() + " " + words.getXmpy() + " " + words.getXm() + " " + words.getQfrq() + " " + words.getHzhm() + " " + words.getQfjg() + " " + words.getYxqz() + " " + words.getHzqfdd() + " " + words.getGjm());
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        } else if (scanType.contains("HKB")) {
            String base64Str = Utils.imageToBase64(imgPath);
            UpLoadImageOne bean = new UpLoadImageOne();
            bean.setBase64Str(base64Str);
            XHttp.post("/api/Text/HouseholdRegister")
                    .upJson(JsonUtil.toJson(bean))
                    .execute(new CallBackProxy<CustomApiResult<HouseholdRegisterResult>, HouseholdRegisterResult>(new TipCallBack<HouseholdRegisterResult>() {
                        @Override
                        public void onSuccess(HouseholdRegisterResult response) {
                            mLoadingDialog.dismiss();
                            ScanResultFifteenAdapter scanResultFifteenAdapter = new ScanResultFifteenAdapter();
                            list.setAdapter(scanResultFifteenAdapter);
                            List<HouseholdRegisterResult.WordsResultBean> data = new ArrayList<>();
                            data.add(response.getWords_result());
                            scanResultFifteenAdapter.setNewData(data);
                            copy.setVisibility(View.VISIBLE);
                            copy.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    HouseholdRegisterResult.WordsResultBean words = response.getWords_result();
                                    ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                                    // 将文本内容放到系统剪贴板里。
                                    cm.setText(words.getName() + " " + words.getSex() + " " + words.getBirthday() + " " + words.getNation() + " " + words.getCardNo() + " " + words.getRelationship() + " " + words.getBirthAddress());
                                    XToastUtils.success("复制成功");
                                }
                            });
                        }

                        @Override
                        public void onError(ApiException e) {
                            super.onError(e);
                            mLoadingDialog.dismiss();
                        }
                    }) {
                    });

        }

    }
}
